package com.exercise.proxytest;

import com.fun.frame.SourceCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

public class AutoLogProxy extends SourceCode implements InvocationHandler {

    private static Logger logger = LoggerFactory.getLogger(AutoLogProxy.class);

    private final Object drive;

    public AutoLogProxy(Object invocationTarget) {
        this.drive = invocationTarget;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        logger.warn("调用方法:{},参数:{}",method.getName(), Arrays.toString(args));
        return method.invoke(drive, args);
    }


}
